/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.hibernate.model.dao;

import hibernate.pojo.Dondathang;
import hibernate.pojo.Sanpham;
import hibernate.util.HibernateUtil;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
/**
 *
 * @author phathuynh
 */
public class AdminDonDatHangDAO {
    //<editor-fold defaultstate="collapsed" desc="1. Cập nhật tình trang giao hàng">
     public static boolean updateOrderState(Dondathang order){
         Session session = HibernateUtil.getSessionFactory().openSession();
         Transaction tran = null;
         try{
             tran = session.beginTransaction();
             session.update(order);
             tran.commit();
         }catch(Exception hex){
             System.err.print(hex);
             tran.rollback();
             return false;
         }
         finally {
             session.close();
         }
         return true;
     }
     //</editor-fold>
     
     //<editor-fold defaultstate="collapsed" desc="2. Get order by customer ID">
     public static Dondathang getOrderByCustomerID(int maKhachHang)
     {
         
         Dondathang order = null;
         Session session = HibernateUtil.getSessionFactory().openSession();
         try
         {
             String hql = "from Dondathang where khachhang.maKhachHang=maKhachHang";
             Query query = session.createQuery(hql);
             query.setInteger("maKhachHang", maKhachHang);
             Object ob = query.uniqueResult();
             order = (Dondathang)ob;
         }
         catch(HibernateException hex) {
             System.err.print(hex);
         }
         finally{
             session.close();
         }
         return order;
     }
     //</editor-fold>
    
}
